home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / fl_set_fonts_win32.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  3.2 KB  |  92 lines

  1. //
  2. // "$Id: fl_set_fonts_win32.cxx,v 1.5 1999/01/07 19:17:42 mike Exp $"
  3. //
  4. // WIN32 font utilities for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // This function fills in the fltk font table with all the fonts that
  27. // are found on the X server.  It tries to place the fonts into families
  28. // and to sort them so the first 4 in a family are normal, bold, italic,
  29. // and bold italic.
  30.  
  31. #include <FL/Fl.H>
  32. #include <FL/win32.H>
  33. #include "Fl_Font.H"
  34. #include <ctype.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37.  
  38. // turn a stored font name into a pretty name:
  39. const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
  40.   const char* p = fl_fonts[fnum].name;
  41.   if (!p || !*p) {if (ap) *ap = 0; return "";}
  42.   int type;
  43.   switch (*p) {
  44.   case 'B': type = FL_BOLD; break;
  45.   case 'I': type = FL_ITALIC; break;
  46.   case 'P': type = FL_BOLD | FL_ITALIC; break;
  47.   default:  type = 0; break;
  48.   }
  49.   if (!type) return p+1;
  50.   static char *buffer; if (!buffer) buffer = new char[128];
  51.   strcpy(buffer, p+1);
  52.   if (type & FL_BOLD) strcat(buffer, " bold");
  53.   if (type & FL_ITALIC) strcat(buffer, " italic");
  54.   return buffer;
  55. }
  56.  
  57. static int fl_free_font = FL_FREE_FONT;
  58.  
  59. static int CALLBACK enumcb(ENUMLOGFONT FAR *lpelf,
  60.   NEWTEXTMETRIC FAR *lpntm, int FontType, LPARAM p) {
  61.   if (!p && lpelf->elfLogFont.lfCharSet != ANSI_CHARSET) return 1;
  62.   char *n = (char*)(lpelf->elfFullName);
  63.   for (int i=0; i<FL_FREE_FONT; i++) // skip if one of our built-in fonts
  64.     if (!strcmp(Fl::get_font_name((Fl_Font)i),n)) return 1;
  65.   char buffer[128];
  66.   strcpy(buffer+1, n);
  67.   buffer[0] = ' '; Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer));
  68.   if (lpelf->elfLogFont.lfWeight <= 400)
  69.     buffer[0] = 'B', Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer));
  70.   buffer[0] = 'I'; Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer));
  71.   if (lpelf->elfLogFont.lfWeight <= 400)
  72.     buffer[0] = 'P', Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer));
  73.   return 1;
  74. }
  75.  
  76. Fl_Font Fl::set_fonts(const char* xstarname) {
  77.   EnumFontFamilies(fl_gc, NULL, (FONTENUMPROC)enumcb, xstarname != 0);
  78.   return (Fl_Font)fl_free_font;
  79. }
  80.  
  81. int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
  82.   // pretend all fonts are scalable (most are and I don't know how
  83.   // to tell anyways)
  84.   static int array[1];
  85.   sizep = array;
  86.   return 1;
  87. }
  88.  
  89. //
  90. // End of "$Id: fl_set_fonts_win32.cxx,v 1.5 1999/01/07 19:17:42 mike Exp $".
  91. //
  92.